package bjtu.wms.wmstest.controller;

import bjtu.wms.wmstest.entity.User;
import bjtu.wms.wmstest.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;

@Controller
public class RegisterController {
    @Autowired
    private UserService userService;

    @GetMapping("/register")
    public String showRegisterForm() {
        return "register";
    }

    @PostMapping("/register")
    public String register(HttpServletRequest request,
                           @RequestParam String name, @RequestParam String password) {
        User user = new User(name, password,100);

        //原来是save，insert参数是有phone的，不行记得换
        userService.insert(user);

        request.getSession().setAttribute("user", user);
        return "index";
    }
}
